//
//  XTMainTabBarController.swift
//  HrenryWeibo
//
//  Created by 熊涛 on 16/5/10.
//  Copyright © 2016年 熊涛. All rights reserved.
//

import UIKit
import SVProgressHUD

class XTMainTabBarController: UITabBarController {

    //MARK: - lifecycle
    
    override func viewDidLoad() {
        super.viewDidLoad()
//        tabBar.tintColor = UIColor.orangeColor()
        
        //添加子控制器
        setChildViewController()
        
        
        //自定义TabBar
        let Tabbar = XTMainTabBar()
        Tabbar.btnCallBack = {
            print("点击了加号按钮")
            
            let composeVC = UINavigationController(rootViewController: XTComposeViewController())
            
            self.presentViewController(composeVC, animated: true, completion: nil)
            
        }
        setValue(Tabbar, forKey: "tabBar")
//        tabBar.barTintColor = UIColor.grayColor()
//        tabBar.translucent = false
//        tabBar.alpha = 1
//        tabBar.addSubview(btn)
    }


    
    
    //MARK: - 给TabBarController添加子控制器
    
    //添加子控制器
    func setChildViewController() {
    
        //home
        let HomeVC = XTHomeTableViewController()
        setChildViewController(HomeVC,titleField: "首页", imageName: "tabbar_home")
        
        //message
        let MessageVC = XTMessageTableViewController()
        setChildViewController(MessageVC,titleField: "信息", imageName: "tabbar_message_center")
        
        //dicovery
        let DiscoverVC = XTDiscoveryTableViewController()
        setChildViewController(DiscoverVC,titleField: "发现", imageName: "tabbar_discover")
        
        //profile
        let ProfileVC = XTProfileTableViewController()
        setChildViewController(ProfileVC,titleField: "我", imageName: "tabbar_profile")
    }

    
    //
    func setChildViewController(viewVC : XTBaseTableViewController,titleField : String, imageName : String) {
        
//        let viewControler = XTBaseTableViewController()
        viewVC.title = titleField
        viewVC.tabBarItem.image = UIImage(named: imageName)
        viewVC.tabBarItem.selectedImage = UIImage(named:imageName + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        viewVC.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        self.addChildViewController(UINavigationController(rootViewController: viewVC))
    
    }

    
    

    

    
    
}
